<?php

namespace app\index\model;

use think\Model;
use think\Db;
class Warehouse extends Model
{
    protected $autoWriteTimestamp = 'datetime';
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    protected $pk ='id';

    public function getStatusAttr($value)
    {
        $status = [0=>'禁用',1=>'正常'];
        return $status[$value];
    }

    /**
     * 是否存在 代码或者名字的记录
     * @return int|string
     */
    public static function isHasRecord(){
        $post = input('post.');
        $res = Db::name('warehouse')->where(['name'=>$post['name']])->whereOr(['ware_house_code'=>$post['ware_house_code']])->whereOr(['location_code'=>$post['location_code']])->find();
        if(isset($post['id']) && isset($res['id'])) {   //更新操作
             return $res['id']!=$post['id'];
        }
        return $res;
    }
}
